﻿using Server;
using Server.Packets;
using System;
using System.Diagnostics.CodeAnalysis;
using System.IO;

namespace GetThis_Server.Packets
{
    public class S2RandomNumberPacket : Packet
    {
        #region Fields

        /// <summary>
        /// Random number.
        /// </summary>
        private uint m_randomNumber;

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="T:GetThis_Server.Packets.S2RandomNumberPacket" /> class.
        /// </summary>
        public S2RandomNumberPacket()
            : this(0)
        {
        }

        /// <summary>
        /// Initializes a new instance of the <see cref="T:GetThis_Server.Packets.S2RandomNumberPacket" /> class with a given random number.
        /// </summary>
        /// <param name="isIpValid">Indicates ether the Ip is valid.</param>
        /// <param name="randomNumber">A random number.</param>
        internal S2RandomNumberPacket(uint randomNumber)
        {
            m_randomNumber = randomNumber;
        }

        #endregion

        #region Properties

        /// <summary>
        /// Identifier.
        /// </summary>
        protected override byte Id
        {
            get { return 2; }
        }

        #endregion

        #region Methods

        /// <summary>
        /// Reads the raw packet data from the data reader.
        /// </summary>
        /// <param name="reader">Data reader.</param>
        protected override void ReadPacketData(BinaryReader reader)
        {
            m_randomNumber = reader.ReadUInt32();
        }

        /// <summary>
        /// Write the raw packet data to the data writer.
        /// </summary>
        /// <param name="writer">Data writer.</param>
        protected override void WritePacketData(BinaryWriter writer)
        {
            writer.Write(m_randomNumber);
        }

        /// <summary>
        /// Converts this instance to its equivalent string representation.
        /// </summary>
        /// <returns>The string representation of the value of this instance.</returns>
        public override string ToString()
        {
            return String.Format("S2RandomNumberPacket - Id : {0}", m_randomNumber);
        }

        #endregion
    }
}
